WordPress

推荐列表 站点导航

当前位置:首页 > 建站教程 > WordPress >

WordPress实现的首页幻灯片展示功能示例

来源:网络整理  作者:  发布时间:2020-12-18 12:19
对于WordPress拓展性这么优秀的程序来说,是没有什么不能实现的。很多在建站的时候,都会选择在首页使用幻灯片,...
/* 这里也需要改一下,设置需要创建的Post Meta Box叫什么名字,显示在什么位置 */
'post', // Admin page (or post type)
add_action( 'load-post.php', 'sola_post_meta_boxes_setup' );
echo '<input type="hidden" value="', wp_create_nonce(basename(__FILE__)), '" />';

接下来修改slider.php,使用post meta box实现,就需要根据post的meta信息搜索幻灯片,代码如下

break;

}
);
}
update_post_meta($post_id, $field['id'], $new);
'meta_key' => 'sola-post-slider',
}
'sola_seo_box_format', // Callback function

用get_posts()和meta_query参数结合,就可以达到目的,有了数据,直接循环输出就行

foreach ($fields as $field) {

希望本文所述对大家基于wordpress的程序设计有所帮助。

'type' => 'checkbox',
echo '<table>';
}
echo '<input type="radio" value="' . $option['value'] . '"' . ( $meta == $option['value'] ? ' checked="checked"' : '' ) . ' />' . $option['name'];
// get current post meta data
case 'checkbox':
后面的代码会自动根据数组填充的内容创建Post Meta Box */
echo '</select>';
}
case 'radio':
switch ($field['type']) {
break;
function sola_post_meta_boxes_setup() {
case 'text':
array(
// Use nonce for verification
function sola_save_post_meta_boxes($post_id) {

2.读取幻灯片文章

break;
$post_type = get_post_type_object( $post->post_type );
'sola-post-slider-class', // Unique ID
)
//Get the post type object.
foreach ($field['options'] as $option) {
$new = $_POST[$field['id']];
//Check autosave
delete_post_meta($post_id, $field['id'], $old);
/* Create one or more meta boxes to be displayed on the post editor screen. */

1.创建Post Meta Box

function sola_seo_box_format(){

WordPress实现的首页幻灯片展示功能示例 (https://www.wpmee.com/) WordPress使用教程 第2张

//Check permissions
return $post_id;
$old = get_post_meta($post_id, $field['id'], true);
add_action( 'load-post-new.php', 'sola_post_meta_boxes_setup' );
echo '<select>';
if (!wp_verify_nonce($_POST['sola_meta_box_nonce'], basename(__FILE__))) {
'. $field['desc'];
if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
echo '<input type="checkbox"' . ( $meta ? ' checked="checked"' : '' ) . ' />';
echo '<input type="text" value="'. ($meta ? $meta : $field['default']) . '" size="30" />'. '
'posts_per_page'   => 4,

这段代码会在文章创建和编辑页面创建如下所示的Post Meta Box :

WordPress实现的首页幻灯片展示功能示例 (https://www.wpmee.com/) WordPress使用教程 第1张

add_meta_box(
echo '</table>';
break;
echo '<td>'.'</tr>';
'id' => 'sola-post-slider',
}  
} elseif ('' == $new && $old) {
'<th><label for="'. $field['id'] .'">'. $field['name']. '</strong></label></th>'.
echo '<option '. ( $meta == $option ? ' selected="selected"' : '' ) . '>'. $option . '</option>';
case 'textarea':
$fields = array(
add_action( 'add_meta_boxes', 'sola_add_post_meta_boxes' );
'desc' => 'Check this box and make the post a slider',
function sola_add_post_meta_boxes() {
global $fields, $post;
'meta_value' => 'on',
break;

主要是使用了WordPress的自定义文章字段的功能来判断是否需要显示在首页:

global $fields,$post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
'default' => ''
/* Meta box setup function. */
/* Fire our meta box setup function on the post editor screen. */
add_action( 'save_post', 'sola_save_post_meta_boxes', 10, 2 );
/* 这是需要修改的两处之一,本功能只需要一个checkbox,将checkbox的title、id等属性填充到$fields数组中,

写文章时,勾选在首页显示幻灯片,这篇文章就会自动推送到首页幻灯片中。

//Verify nonce
}
'default' // Priority
'name' => __('是否在首页幻灯显示'),
__('首页幻灯片'), // Title
}

对于WordPress拓展性这么优秀的程序来说,是没有什么不能实现的。很多在建站的时候,都会选择在首页使用幻灯片,可以展示比较醒目的内容。今天就来一个首页幻灯片的制作教程,相信幻灯片在各种企业包括个人网站上面用处还是很大的,做完之后效果和本站首页的一样。

'<td>';
'. $field['desc'];
}
if ($new && $new != $old) {
echo '<textarea cols="60" rows="4">'. ($meta ? $meta : $field['default']) . ''. '
case 'select':
foreach ($field['options'] as $option) {
}
echo '<tr>'.
query_posts($args);
 
}
foreach ($fields as $field) {
$meta = get_post_meta($post->ID, $field['id'], true);
}
return $post_id;
'side', // Context
);
/* Add meta boxes on the 'add_meta_boxes' hook. */
$args = array(
);

相关热词: 功能

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jz/wp/5184.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

WordPress实现的首页幻灯片展示功能示例

2020-12-18 编辑:

/* 这里也需要改一下,设置需要创建的Post Meta Box叫什么名字,显示在什么位置 */
'post', // Admin page (or post type)
add_action( 'load-post.php', 'sola_post_meta_boxes_setup' );
echo '<input type="hidden" value="', wp_create_nonce(basename(__FILE__)), '" />';

接下来修改slider.php,使用post meta box实现,就需要根据post的meta信息搜索幻灯片,代码如下

break;

}
);
}
update_post_meta($post_id, $field['id'], $new);
'meta_key' => 'sola-post-slider',
}
'sola_seo_box_format', // Callback function

用get_posts()和meta_query参数结合,就可以达到目的,有了数据,直接循环输出就行

foreach ($fields as $field) {

希望本文所述对大家基于wordpress的程序设计有所帮助。

'type' => 'checkbox',
echo '<table>';
}
echo '<input type="radio" value="' . $option['value'] . '"' . ( $meta == $option['value'] ? ' checked="checked"' : '' ) . ' />' . $option['name'];
// get current post meta data
case 'checkbox':
后面的代码会自动根据数组填充的内容创建Post Meta Box */
echo '</select>';
}
case 'radio':
switch ($field['type']) {
break;
function sola_post_meta_boxes_setup() {
case 'text':
array(
// Use nonce for verification
function sola_save_post_meta_boxes($post_id) {

2.读取幻灯片文章

break;
$post_type = get_post_type_object( $post->post_type );
'sola-post-slider-class', // Unique ID
)
//Get the post type object.
foreach ($field['options'] as $option) {
$new = $_POST[$field['id']];
//Check autosave
delete_post_meta($post_id, $field['id'], $old);
/* Create one or more meta boxes to be displayed on the post editor screen. */

1.创建Post Meta Box

function sola_seo_box_format(){

WordPress实现的首页幻灯片展示功能示例 (https://www.wpmee.com/) WordPress使用教程 第2张

//Check permissions
return $post_id;
$old = get_post_meta($post_id, $field['id'], true);
add_action( 'load-post-new.php', 'sola_post_meta_boxes_setup' );
echo '<select>';
if (!wp_verify_nonce($_POST['sola_meta_box_nonce'], basename(__FILE__))) {
'. $field['desc'];
if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
echo '<input type="checkbox"' . ( $meta ? ' checked="checked"' : '' ) . ' />';
echo '<input type="text" value="'. ($meta ? $meta : $field['default']) . '" size="30" />'. '
'posts_per_page'   => 4,

这段代码会在文章创建和编辑页面创建如下所示的Post Meta Box :

WordPress实现的首页幻灯片展示功能示例 (https://www.wpmee.com/) WordPress使用教程 第1张

add_meta_box(
echo '</table>';
break;
echo '<td>'.'</tr>';
'id' => 'sola-post-slider',
}  
} elseif ('' == $new && $old) {
'<th><label for="'. $field['id'] .'">'. $field['name']. '</strong></label></th>'.
echo '<option '. ( $meta == $option ? ' selected="selected"' : '' ) . '>'. $option . '</option>';
case 'textarea':
$fields = array(
add_action( 'add_meta_boxes', 'sola_add_post_meta_boxes' );
'desc' => 'Check this box and make the post a slider',
function sola_add_post_meta_boxes() {
global $fields, $post;
'meta_value' => 'on',
break;

主要是使用了WordPress的自定义文章字段的功能来判断是否需要显示在首页:

global $fields,$post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
'default' => ''
/* Meta box setup function. */
/* Fire our meta box setup function on the post editor screen. */
add_action( 'save_post', 'sola_save_post_meta_boxes', 10, 2 );
/* 这是需要修改的两处之一,本功能只需要一个checkbox,将checkbox的title、id等属性填充到$fields数组中,

写文章时,勾选在首页显示幻灯片,这篇文章就会自动推送到首页幻灯片中。

//Verify nonce
}
'default' // Priority
'name' => __('是否在首页幻灯显示'),
__('首页幻灯片'), // Title
}

对于WordPress拓展性这么优秀的程序来说,是没有什么不能实现的。很多在建站的时候,都会选择在首页使用幻灯片,可以展示比较醒目的内容。今天就来一个首页幻灯片的制作教程,相信幻灯片在各种企业包括个人网站上面用处还是很大的,做完之后效果和本站首页的一样。

'<td>';
'. $field['desc'];
}
if ($new && $new != $old) {
echo '<textarea cols="60" rows="4">'. ($meta ? $meta : $field['default']) . ''. '
case 'select':
foreach ($field['options'] as $option) {
}
echo '<tr>'.
query_posts($args);
 
}
foreach ($fields as $field) {
$meta = get_post_meta($post->ID, $field['id'], true);
}
return $post_id;
'side', // Context
);
/* Add meta boxes on the 'add_meta_boxes' hook. */
$args = array(
);

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jz/wp/5184.shtml

相关文章

风云图片

推荐阅读

返回WordPress频道首页